#pragma once

#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <float.h>
#include "common.h"
#include "OrNodeModel.h"
#include "LeafNodeModel.h"
#include "TMatrix.h"

using	namespace	std;

class CAndNodeModel
{
	public:
		typedef struct tagTriplet
		{
			int			p1, p2, p3;					// index of child
			int			m1, m2, m3;					// index of model of child
			double		gamma;						// the weight of triplet

			vector<double>	feature;
			vector<double>	variance;
		} TripletType;

		typedef struct tagSubNodeInfo				// The information between center and leaf nodes
		{
			int			LeafID;
			double		len;
			double		ori;
		} SubNodeInfoType;

	public:
		CAndNodeModel(void);
		~CAndNodeModel(void);

	public:
		int							AndNodeID;						// ID
		int							NodeType;						// 0: Leaf Node;  1: Or Node

		vector<int>					Children;						// when NodeType = 1
		int							LeafIndex;						// when NodeType = 0;

		vector<TripletType>			triplets;						// triplets
		double						AppearanceWeight;

		vector<SubNodeInfoType>		LeafCenterInfo;

		TMatrix<double>				NodeLenInfo;					// the length of centers of child_node
		TMatrix<double>				NodeDirInfo;					// the direct of centers of child_node
		vector<int>					NodeModelIndex;					// the index of candidate model in the list
		vector<int>					MissLeafNode;					// the leaf nodes need to fill in while the node is missing
		vector<double>				Threshold;						// for pruning
		int							ModelCount;						// the total number of candidate models (children)
		int							Level;							// the level of the node

	public:
		int		ReadAndNodeModel(FILE *fpFile, int RuleCount);
		int		SaveAndNodeModel(FILE *fpFile, int RuleCount);

		int		MakeMissInformation(ModelTreeType &model, int Level);
};

